package com.tie.catalogo;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.view.Menu;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class Ajustes extends Activity {
	EditText licencia;
	SharedPreferences prefs;
	TextView uid, valor;
	SeekBar barra;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ajustes);
		licencia = (EditText)findViewById(R.id.licenciaTxt);
		prefs = getSharedPreferences("ajustes", MODE_PRIVATE);
		uid = (TextView)findViewById(R.id.uid);
		uid.setText(Secure.getString(this.getContentResolver(),Secure.ANDROID_ID));
		licencia.setText(prefs.getString("key", ""));
		barra = (SeekBar)findViewById(R.id.barra1);
		valor = (TextView)findViewById(R.id.imgSize);
		barra.setMax(200);
		barra.setProgress(prefs.getInt("imgSize", 70));
		barra.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				valor.setText(Integer.toString(progress));
				SharedPreferences.Editor editor = prefs.edit();
				editor.putInt("imgSize", progress);
				editor.commit();
				
			}
		});
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_ajustes, menu);
		return true;
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		SharedPreferences.Editor editor = prefs.edit();
		editor.putString("key", licencia.getText().toString());
		editor.commit();
	}
}
